package com.jason.campusinn.view.GLView;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.opengl.GLU;
import android.opengl.GLUtils;
import android.os.Build;
import android.os.Build.VERSION;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.yuandian.wanna.R;
import com.yuandian.wanna.utils.LogUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class MySurfaceView extends GLSurfaceView{
    private final float TOUCH_SCALE_FACTOR = 180.0f/320;//角度缩放比例
    private SceneRenderer mRenderer;//场景渲染器

    private float mPreviousX;//上次的触控位置X坐标

    @Override
    public void onPause() {
        super.onPause();
    }

    public MySurfaceView(Context context) {
        super(context);

//        setZOrderOnTop(true);
//        setEGLConfigChooser(8, 8, 8, 8, 16, 0);
//        getHolder().setFormat(PixelFormat.TRANSLUCENT);
        mRenderer = new SceneRenderer();	//创建场景渲染器
        setRenderer(mRenderer);				//设置渲染器
        setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);//设置渲染模式为主动渲染
    }

    public MySurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);

//        setZOrderOnTop(true);
//        setEGLConfigChooser(8, 8, 8, 8, 16, 0);
//        getHolder().setFormat(PixelFormat.TRANSLUCENT);
        mRenderer = new SceneRenderer();	//创建场景渲染器
        setRenderer(mRenderer);				//设置渲染器
        setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);//设置渲染模式为主动渲染
    }

    float mDownX;
    float mDownY;
    boolean mIsMoveUp = false;
    //触摸事件回调方法
    @Override
    public boolean onTouchEvent(MotionEvent e) {
        float x = e.getX();
        switch (e.getAction()) {
            case MotionEvent.ACTION_MOVE:
                mIsMoveUp = false;
                float dx = x - mPreviousX;//计算触控笔X位移
                mRenderer.angle = (mRenderer.angle + (dx * TOUCH_SCALE_FACTOR))%360;//设置沿x轴旋转角度
                requestRender();//重绘画面
                break;
            case MotionEvent.ACTION_DOWN:
                mIsMoveUp = false;
                mDownX = e.getX();
                mDownY = e.getY();
                break;
            case MotionEvent.ACTION_UP:
                mIsMoveUp = true;
                if(Math.abs(mDownX-e.getX())<10&&
                        Math.abs(mDownY-e.getY())<10
                        )
                {
                    showSel();
                }
                break;
        }
        mPreviousX = x;//记录触控笔位置
        return true;
    }

    public int showSel()
    {
        int rtn = 0;

        if(mRenderer.m_b_big)
        {
//            Log.e("showSel", "后被选择:"+String.valueOf(mRenderer.mTextureRectList.get(mRenderer.m_b_index).resindex));
            rtn = mRenderer.mTextureRectList.get(mRenderer.m_b_index).resindex;
        } else {
            if(mRenderer.m_r_big)
            {
//                Log.e("showSel", "右被选择:"+String.valueOf(mRenderer.mTextureRectList.get(mRenderer.m_r_index).resindex));
                rtn = mRenderer.mTextureRectList.get(mRenderer.m_r_index).resindex;
            } else {
                if(mRenderer.m_f_big)
                {
//                    Log.e("showSel", "前被选择:"+String.valueOf(mRenderer.mTextureRectList.get(mRenderer.m_f_index).resindex));
                    rtn = mRenderer.mTextureRectList.get(mRenderer.m_f_index).resindex;
                } else {
                    if(mRenderer.m_l_big)
                    {
//                        Log.e("showSel", "左被选择:"+String.valueOf(mRenderer.mTextureRectList.get(mRenderer.m_l_index).resindex));
                        rtn = mRenderer.mTextureRectList.get(mRenderer.m_l_index).resindex;
                    }
                }
            }
        }


        return rtn;
    }

    private class SceneRenderer implements Renderer
    {

        public boolean mInit = true;
        public boolean mReLoadTexture = false;

        TextureRect trOneXOne;//1x1贴图矩形
        private ArrayList<TextureRect> mTextureRectList;
        private ArrayList<TextureRect> mBlurTextureRectList;

        float angle=0;//总旋转角度

        public boolean m_b_changed = false;
        public boolean m_l_changed = false;
        public boolean m_f_changed = false;
        public boolean m_r_changed = false;

        public boolean m_b_big = false;
        public boolean m_l_big = false;
        public boolean m_f_big = false;
        public boolean m_r_big = false;
//        int m_b_index = 0;
//        int m_l_index = 1;
//        int m_f_index = 2;
//        int m_r_index = 3;
        int m_b_index = 2;
        int m_l_index = 3;
        int m_f_index = 0;
        int m_r_index = 1;
        int mindex = 0;

        public int m_num_type = 3;

        private float getscale_f2(float angle)
        {
            float rtn = 1.0f;
            float abs_angle = Math.abs(angle);

            if(abs_angle<180)
            {
                rtn = base_small43 + (base_small41-base_small43)*(180.0f-abs_angle)/135.0f;
            } else {
                rtn = base_small43 + (base_small41-base_small43)*(abs_angle-180.0f)/135.0f;
            }

            return rtn;
        }
        private float getscale_f(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = Math.abs(angle);

            if(abs_angle<45)
            {
                rtn = base_small41 + (base_small42-base_small41)*(45.0f-abs_angle)/45.0f;
            } else {
                rtn = base_small41 + (base_small42-base_small41)*(abs_angle-315.0f)/45.0f;
            }

            return rtn;
        }

        private float getscale_l2(float angle)
        {
            float rtn = 1.0f;

            if(angle>0)
            {
                if(angle>135)
                {
                    if(angle<270)
                    {
                        rtn = base_small43 + (base_small41-base_small43)*(270.0f-angle)/135.0f;
                    } else {
                        rtn = base_small43 + (base_small41-base_small43)*(angle-270.0f)/135.0f;
                    }
                } else {
                    if(angle<45)
                    {
                        rtn = base_small43 + (base_small41-base_small43)*(angle+90.0f)/135.0f;
                    }
                }
            } else {

                if(angle>-90)
                {
                    rtn = base_small41 - (base_small41-base_small43)*(45-angle)/135.0f;
                } else {
                    if(angle>-315)
                    {
                        rtn = base_small43 + (base_small41-base_small43)*(Math.abs(angle)-90)/135.0f;
                    } else {
                        rtn = base_small41 - (base_small41-base_small43)*(45-(angle + 360.0f)%360)/135.0f;
                    }
                }
            }

            return rtn;
        }
        private float getscale_l(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = (angle + 360.0f)%360;

            rtn = base_small42 - (base_small42-base_small41)*Math.abs((abs_angle - 90.0f))/45.0f;
            return rtn;
        }

        private float getscale_b2(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = Math.abs(angle);

            if(abs_angle<135)
            {
                rtn = base_small41 - (base_small41-base_small43)*(135.0f-abs_angle)/135.0f;
            } else {
                if(abs_angle>225)
                {
                    rtn = base_small41 - (base_small41-base_small43)*(abs_angle-225.0f)/135.0f;
                }
            }

            return rtn;
        }
        private float getscale_b(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = Math.abs(angle);

            if(abs_angle<180)
            {
                rtn = base_small42 - (base_small42-base_small41)*(180.0f-abs_angle)/45.0f;
            } else {
                rtn = base_small42 - (base_small42-base_small41)*(abs_angle-180.0f)/45.0f;
            }

            return rtn;
        }

        private float getscale_r2(float angle)
        {
            float rtn = 1.0f;

            if(angle>0)
            {
                if(angle>90)
                {
                    if(angle<225)
                    {
                        rtn = base_small43 + (base_small41-base_small43)*(angle-90)/135.0f;
                    } else {
                        if(angle>315)
                        {
                            rtn = base_small41 - (base_small41-base_small43)*(angle-315.0f)/135.0f;
                        }
                    }
                } else {
                    rtn = base_small41 - (base_small41-base_small43)*(angle+45.0f)/135.0f;
                }
            } else {

                if(angle>-90)
                {
                    rtn = base_small41 - (base_small41-base_small43)*(45+angle)/135.0f;
                } else {
                    if(angle>-270)
                    {
                        rtn = base_small41 - (base_small41-base_small43)*(Math.abs(angle)-135.0f)/135.0f;
                    } else {
                        rtn = base_small43 + (base_small41-base_small43)*(Math.abs(angle)-270.0f)/135.0f;
                    }
                }
            }

            return rtn;
        }
        private float getscale_r(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = (angle + 360.0f)%360;

            rtn = base_small42 - (base_small42-base_small41)*Math.abs((abs_angle - 270.0f))/45.0f;

            return rtn;
        }

        private float radius = 2.0f;
        private float base_small41 = 0.7f;//四个物体,第二行2
        private float base_small42 = 1.5f;//四个物体,第一行1
        private float base_small43 = 0.6f;//四个物体,第三行3

        private float base_small31 = 0.7f;//三个物体,第二行
        private float base_small32 = 1.5f;//三个物体,第一行

        private float x_3_len = (float) (radius * Math.sin(60*Math.PI/180));
        private float z_3_len = (float) (radius * Math.sin(30*Math.PI/180));

        private float getscale_f3(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = Math.abs(angle);

            if(abs_angle<60)
            {
                rtn = base_small31 + (base_small32-base_small31)*(60.0f-abs_angle)/60.0f;
            } else {
                rtn = base_small31 + (base_small32-base_small31)*(abs_angle-300.0f)/60.0f;
            }

            return rtn;
        }

        private float getscale_l3(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = (angle + 360.0f)%360;

            rtn = base_small32 - (base_small32-base_small31)*Math.abs((abs_angle - 120.0f))/60.0f;
            return rtn;
        }

        private float getscale_r3(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = (angle + 360.0f)%360;

            rtn = base_small32 - (base_small32-base_small31)*Math.abs((abs_angle - 240.0f))/60.0f;

            return rtn;
        }


        private float gettrans_f3(float angle)
        {
            float rtn = 1.0f;

            angle = Math.abs(angle);

            if(angle<120)
            {
                rtn = mtransz4_3*(120.0f-angle)/120.0f;
            } else {
                rtn = mtransz4_3*(angle-240.0f)/120.0f;
            }

            return rtn;
        }

        private float gettrans_l3(float angle)
        {
            float rtn = 1.0f;

            if(angle<0)
            {
                float abs_angle = Math.abs(angle);
                if(abs_angle<240.0f)
                {
                    rtn = mtransz4_3*(abs_angle-120.0f)/120.0f;
                } else {
                    rtn = mtransz4_3 - mtransz4_3*(abs_angle-240.0f)/120.0f;
                }
            } else {
                if(angle<120.0f)
                {
                    rtn = mtransz4_3 - mtransz4_3*(120.0f-angle)/120.0f;
                } else {
                    rtn = mtransz4_3*(240.0f-angle)/120.0f;
                }
            }

            return rtn;
        }

        private float gettrans_r3(float angle)
        {
            float rtn = 1.0f;

            if(angle<0)
            {
                float abs_angle = Math.abs(angle);
                if(abs_angle<120.0f)
                {
                    rtn = mtransz4_3 - mtransz4_3*(120.0f-abs_angle)/120.0f;
                } else {
                    rtn = mtransz4_3 - mtransz4_3*(abs_angle-120.0f)/120.0f;
                }
            } else {

                if(angle==0)
                {
                    angle = 360.0f;
                }

                if(angle<240.0f)
                {
                    rtn = mtransz4_3 - mtransz4_3*(240.0f-angle)/120.0f;
                } else {
                    rtn = mtransz4_3 - mtransz4_3*(angle - 240.0f)/120.0f;
                }
            }

            return rtn;
        }

        //private
        private void rotation3Objects(GL10 gl)
        {
            m_l_index = 2;
            m_f_index = 0;
            m_r_index = 1;
            //回弹
            if(mIsMoveUp){
                if(angle>0)
                {
                    if(angle<60)
                    {
                        angle=0;
                    } else {
                        if(angle<120)
                        {
                            angle = 120;
                        } else {
                            if(angle<180)
                            {
                                angle = 120;
                            } else {
                                if(angle<240)
                                {
                                    angle=240;
                                } else {
                                    if(angle<300)
                                    {
                                        angle=240;
                                    } else {
                                        if(angle<360)
                                        {
                                            angle=0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if(angle>-60)
                    {
                        angle=0;
                    } else {
                        if(angle>-120)
                        {
                            angle = -120;
                        } else {
                            if(angle>-180)
                            {
                                angle = -120;
                            } else {
                                if(angle>-240)
                                {
                                    angle=-240;
                                } else {
                                    if(angle>-300)
                                    {
                                        angle=-240;
                                    } else {
                                        if(angle>-360)
                                        {
                                            angle=0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }


            if(angle>0)//从左向右运动
            {

                if(angle<60)
                {
                    //右
                    gl.glPushMatrix();
                    gl.glTranslatef(x_3_len, 0, -z_3_len);
                    gl.glScalef(base_small31, base_small31, base_small31);
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //左
                    gl.glPushMatrix();
                    gl.glTranslatef(-x_3_len, -1.0f*gettrans_l3(angle), -z_3_len);
                    gl.glScalef(base_small31, base_small31, base_small31);
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //前
                    gl.glPushMatrix();
                    gl.glTranslatef(0, -1.0f*gettrans_f3(angle), radius);
                    gl.glScalef(1.0f*getscale_f3(angle), 1.0f*getscale_f3(angle), 1.0f*getscale_f3(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mTextureRectList.get(m_f_index).drawSelf(gl);
                    gl.glPopMatrix();

                    m_b_big = false;
                    m_l_big = false;
                    m_f_big = true;
                    m_r_big = false;
                } else {
                    if(angle<120)
                    {

                        //右
                        gl.glPushMatrix();
                        gl.glTranslatef(x_3_len, 0, -z_3_len);
                        gl.glScalef(base_small31, base_small31, base_small31);
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                        gl.glPopMatrix();

                        //前
                        gl.glPushMatrix();
                        gl.glTranslatef(0, -1.0f*gettrans_f3(angle), radius);
                        gl.glScalef(base_small31, base_small31, base_small31);
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                        gl.glPopMatrix();

                        //左
                        gl.glPushMatrix();
                        gl.glTranslatef(-x_3_len, -1.0f*gettrans_l3(angle), -z_3_len);
                        gl.glScalef(1.0f*getscale_l3(angle), 1.0f*getscale_l3(angle), 1.0f*getscale_l3(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mTextureRectList.get(m_l_index).drawSelf(gl);
                        gl.glPopMatrix();

                        m_b_big = false;
                        m_l_big = true;
                        m_f_big = false;
                        m_r_big = false;

                    } else {

                        if(angle<180)
                        {
                            //前
                            gl.glPushMatrix();
                            gl.glTranslatef(0, 0, radius);
                            gl.glScalef(base_small31, base_small31, base_small31);
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                            gl.glPopMatrix();

                            //右
                            gl.glPushMatrix();
                            gl.glTranslatef(x_3_len, -1.0f*gettrans_r3(angle), -z_3_len);
                            gl.glScalef(base_small31, base_small31, base_small31);
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                            gl.glPopMatrix();

                            //左
                            gl.glPushMatrix();
                            gl.glTranslatef(-x_3_len, -1.0f*gettrans_l3(angle), -z_3_len);
                            gl.glScalef(1.0f*getscale_l3(angle), 1.0f*getscale_l3(angle), 1.0f*getscale_l3(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mTextureRectList.get(m_l_index).drawSelf(gl);
                            gl.glPopMatrix();


                            m_b_big = false;
                            m_l_big = true;
                            m_f_big = false;
                            m_r_big = false;
                        } else {
                            if(angle<240)
                            {

                                //前
                                gl.glPushMatrix();
                                gl.glTranslatef(0, 0, radius);
                                gl.glScalef(base_small31, base_small31, base_small31);
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                gl.glPopMatrix();



                                //左
                                gl.glPushMatrix();
                                gl.glTranslatef(-x_3_len, -1.0f*gettrans_l3(angle), -z_3_len);
                                gl.glScalef(base_small31, base_small31, base_small31);
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                gl.glPopMatrix();

                                //右
                                gl.glPushMatrix();
                                gl.glTranslatef(x_3_len, -1.0f*gettrans_r3(angle), -z_3_len);
                                gl.glScalef(1.0f*getscale_r3(angle), 1.0f*getscale_r3(angle), 1.0f*getscale_r3(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mTextureRectList.get(m_r_index).drawSelf(gl);
                                gl.glPopMatrix();

                                m_b_big = false;
                                m_l_big = false;
                                m_f_big = false;
                                m_r_big = true;
                            } else {
                                if(angle<300)
                                {
                                    //左
                                    gl.glPushMatrix();
                                    gl.glTranslatef(-x_3_len, 0, -z_3_len);
                                    gl.glScalef(base_small31, base_small31, base_small31);
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    //前
                                    gl.glPushMatrix();
                                    gl.glTranslatef(0, -1.0f*gettrans_f3(angle), radius);
                                    gl.glScalef(base_small31, base_small31, base_small31);
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    //右
                                    gl.glPushMatrix();
                                    gl.glTranslatef(x_3_len, -1.0f*gettrans_r3(angle), -z_3_len);
                                    gl.glScalef(1.0f*getscale_r3(angle), 1.0f*getscale_r3(angle), 1.0f*getscale_r3(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mTextureRectList.get(m_r_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    m_b_big = false;
                                    m_l_big = false;
                                    m_f_big = false;
                                    m_r_big = true;
                                } else {
                                    if(angle<360)
                                    {

                                        //左
                                        gl.glPushMatrix();
                                        gl.glTranslatef(-x_3_len, 0, -z_3_len);
                                        gl.glScalef(base_small31, base_small31, base_small31);
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                        gl.glPopMatrix();


                                        //右
                                        gl.glPushMatrix();
                                        gl.glTranslatef(x_3_len, -1.0f*gettrans_r3(angle), -z_3_len);
                                        gl.glScalef(base_small31, base_small31, base_small31);
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                        gl.glPopMatrix();

                                        //前
                                        gl.glPushMatrix();
                                        gl.glTranslatef(0, -1.0f*gettrans_f3(angle), radius);
                                        gl.glScalef(1.0f*getscale_f3(angle), 1.0f*getscale_f3(angle), 1.0f*getscale_f3(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mTextureRectList.get(m_f_index).drawSelf(gl);
                                        gl.glPopMatrix();


                                        m_b_big = false;
                                        m_l_big = false;
                                        m_f_big = true;
                                        m_r_big = false;
                                    }
                                }
                            }
                        }
                    }
                }
            } else {//从右往左运动

                if(Math.abs(angle)<60)
                {
                    //左
                    gl.glPushMatrix();
                    gl.glTranslatef(-x_3_len, 0, -z_3_len);
                    gl.glScalef(base_small31, base_small31, base_small31);
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //右
                    gl.glPushMatrix();
                    gl.glTranslatef(x_3_len, -1.0f*gettrans_r3(angle), -z_3_len);
                    gl.glScalef(base_small31, base_small31, base_small31);
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //前
                    gl.glPushMatrix();
                    gl.glTranslatef(0, -1.0f*gettrans_f3(angle), radius);
                    gl.glScalef(1.0f*getscale_f3(angle), 1.0f*getscale_f3(angle), 1.0f*getscale_f3(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mTextureRectList.get(m_f_index).drawSelf(gl);
                    gl.glPopMatrix();

                    m_b_big = false;
                    m_l_big = false;
                    m_f_big = true;
                    m_r_big = false;
                } else {
                    if(Math.abs(angle)<120)
                    {


                        //左
                        gl.glPushMatrix();
                        gl.glTranslatef(-x_3_len, 0, -z_3_len);
                        gl.glScalef(base_small31, base_small31, base_small31);
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                        gl.glPopMatrix();

                        //前
                        gl.glPushMatrix();
                        gl.glTranslatef(0, -1.0f*gettrans_f3(angle), radius);
                        gl.glScalef(base_small31, base_small31, base_small31);
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                        gl.glPopMatrix();

                        //右
                        gl.glPushMatrix();
                        gl.glTranslatef(x_3_len, -1.0f*gettrans_r3(angle), -z_3_len);
                        gl.glScalef(1.0f*getscale_r3(angle), 1.0f*getscale_r3(angle), 1.0f*getscale_r3(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mTextureRectList.get(m_r_index).drawSelf(gl);
                        gl.glPopMatrix();



                        m_b_big = false;
                        m_l_big = false;
                        m_f_big = false;
                        m_r_big = true;
                    } else {

                        if(Math.abs(angle)<180){
                            //前
                            gl.glPushMatrix();
                            gl.glTranslatef(0, 0, radius);
                            gl.glScalef(base_small31, base_small31, base_small31);
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                            gl.glPopMatrix();

                            //左
                            gl.glPushMatrix();
                            gl.glTranslatef(-x_3_len, -1.0f*gettrans_l3(angle), -z_3_len);
                            gl.glScalef(base_small31, base_small31, base_small31);
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                            gl.glPopMatrix();

                            //右
                            gl.glPushMatrix();
                            gl.glTranslatef(x_3_len, -1.0f*gettrans_r3(angle), -z_3_len);
                            gl.glScalef(1.0f*getscale_r3(angle), 1.0f*getscale_r3(angle), 1.0f*getscale_r3(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mTextureRectList.get(m_r_index).drawSelf(gl);
                            gl.glPopMatrix();

                            m_b_big = false;
                            m_l_big = false;
                            m_f_big = false;
                            m_r_big = true;
                        } else {
                            if(Math.abs(angle)<240){

                                //前
                                gl.glPushMatrix();
                                gl.glTranslatef(0, 0, radius);
                                gl.glScalef(base_small31, base_small31, base_small31);
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                gl.glPopMatrix();


                                //右
                                gl.glPushMatrix();
                                gl.glTranslatef(x_3_len, -1.0f*gettrans_r3(angle), -z_3_len);
                                gl.glScalef(base_small31, base_small31, base_small31);
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                gl.glPopMatrix();

                                //左
                                gl.glPushMatrix();
                                gl.glTranslatef(-x_3_len, -1.0f*gettrans_l3(angle), -z_3_len);

                                gl.glScalef(1.0f*getscale_l3(angle), 1.0f*getscale_l3(angle), 1.0f*getscale_l3(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mTextureRectList.get(m_l_index).drawSelf(gl);
                                gl.glPopMatrix();






                                m_b_big = false;
                                m_l_big = true;
                                m_f_big = false;
                                m_r_big = false;
                            } else {
                                if(Math.abs(angle)<300){
                                    //右
                                    gl.glPushMatrix();
                                    gl.glTranslatef(x_3_len, 0, -z_3_len);
                                    gl.glScalef(base_small31, base_small31, base_small31);
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    //前
                                    gl.glPushMatrix();
                                    gl.glTranslatef(0, -1.0f*gettrans_f3(angle), radius);
                                    gl.glScalef(base_small31, base_small31, base_small31);
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    //左
                                    gl.glPushMatrix();
                                    gl.glTranslatef(-x_3_len, -1.0f*gettrans_l3(angle), -z_3_len);
                                    gl.glScalef(1.0f*getscale_l3(angle), 1.0f*getscale_l3(angle), 1.0f*getscale_l3(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mTextureRectList.get(m_l_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    m_b_big = false;
                                    m_l_big = true;
                                    m_f_big = false;
                                    m_r_big = false;
                                } else {
                                    if(Math.abs(angle)<360)
                                    {

                                        //右
                                        gl.glPushMatrix();
                                        gl.glTranslatef(x_3_len, 0, -z_3_len);
                                        gl.glScalef(base_small31, base_small31, base_small31);
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                        gl.glPopMatrix();



                                        //左
                                        gl.glPushMatrix();
                                        gl.glTranslatef(-x_3_len, -1.0f*gettrans_l3(angle), -z_3_len);
                                        gl.glScalef(base_small31, base_small31, base_small31);
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                        gl.glPopMatrix();

                                        //前
                                        gl.glPushMatrix();
                                        gl.glTranslatef(0, -1.0f*gettrans_f3(angle), radius);
                                        gl.glScalef(1.0f*getscale_f3(angle), 1.0f*getscale_f3(angle), 1.0f*getscale_f3(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mTextureRectList.get(m_f_index).drawSelf(gl);
                                        gl.glPopMatrix();

                                        m_b_big = false;
                                        m_l_big = false;
                                        m_f_big = true;
                                        m_r_big = false;

                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (m_current_sel_index != showSel()) {
                m_current_sel_index = showSel();
//                if (icallBack != null) {
                    icallBack.onSelected(m_current_sel_index);
//                }
//            } else if (showSel() == 0){
//                m_current_sel_index = showSel();
//                icallBack.onSelected(0);

            }
        }

        private int m_current_sel_index = -1;
        private float mtransz4_3 = 1.0f;

        private float gettrans_f(float angle)
        {
            float rtn = 1.0f;

            angle = Math.abs(angle);

            if(angle<90)
            {
                rtn = mtransz4_3*(90.0f-angle)/90.0f;
            } else {
                rtn = mtransz4_3*(angle-270.0f)/90.0f;
            }

            return rtn;
        }

        private float gettrans_l(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = (angle + 360.0f)%360;

            if(abs_angle<90)
            {
                rtn = mtransz4_3 - mtransz4_3*(90.0f-abs_angle)/90.0f;
            } else {
                rtn = mtransz4_3*(180.0f-abs_angle)/90.0f;
            }

            return rtn;
        }

        private float gettrans_b(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = Math.abs(angle);

            if(abs_angle<180)
            {
                rtn = mtransz4_3 - mtransz4_3*(180.0f-abs_angle)/90.0f;
            } else {
                rtn = mtransz4_3 - mtransz4_3*(abs_angle-180)/90.0f;
            }

            return rtn;
        }

        private float gettrans_r(float angle)
        {
            float rtn = 1.0f;

            float abs_angle = (angle + 360.0f)%360;

            if(abs_angle==0)
            {
                abs_angle = 360;
            }
            if(abs_angle>270)
            {
                rtn = mtransz4_3 - mtransz4_3*(abs_angle-270)/90.0f;
            } else {
                rtn = mtransz4_3*(abs_angle - 180.0f)/90.0f;
            }

            return rtn;
        }

//        int m_b_index = 2;
//        int m_l_index = 3;
//        int m_f_index = 0;
//        int m_r_index = 1;
//        int mindex = 4;
        int mindex2 = 0;
        boolean mreadyforchange = true;
        boolean mpre_angleplus = true;
        private void rotation4Objects(GL10 gl)
        {

            //回弹
            if(mIsMoveUp)
            {
                if(angle>0)
                {
                    mreadyforchange = true;
                    if(angle<45)
                    {
                        angle=0;
                    } else {
                        if(angle<90)
                        {
                            angle = 90;
                        } else {
                            if(angle<135)
                            {
                                angle = 90;
                            } else {
                                if(angle<180)
                                {
                                    angle=180;
                                } else {
                                    if(angle<225)
                                    {
                                        angle=180;
                                    } else {
                                        if(angle<270)
                                        {
                                            angle=270;
                                        } else {
                                            if(angle<315)
                                            {
                                                angle=270;
                                            } else {
                                                if(angle<360)
                                                {
                                                    angle=0;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {

                    if(angle<0){
                        mreadyforchange = true;
                        if(angle>-45)
                        {
                            angle=0;
                        } else {
                            if(angle>-90)
                            {
                                angle = -90;
                            } else {
                                if(angle>-135)
                                {
                                    angle = -90;
                                } else {
                                    if(angle>-180)
                                    {
                                        angle=-180;
                                    } else {
                                        if(angle>-225)
                                        {
                                            angle=-180;
                                        } else {
                                            if(angle>-270)
                                            {
                                                angle=-270;
                                            } else {
                                                if(angle>-315)
                                                {
                                                    angle=-270;
                                                } else {
                                                    if(angle>-360)
                                                    {
                                                        angle=0;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }


            //TODO:调整列表顺序，保证正传反转循序一致
            if(m_f_big)
            {
                if(angle!=0)
                {
                    m_l_index = mindex2;
                    m_r_index = mindex;
                }

            } else {
                if(m_l_big)
                {
                    if(angle!=0)
                    {
                        m_b_index = mindex2;
                        m_f_index = mindex;
                    }

                } else {
                    if(m_b_big)
                    {
                        if(angle!=0)
                        {
                            m_r_index = mindex2;
                            m_l_index = mindex;
                        }

                    } else {
                        if(m_r_big)
                        {
                            if(angle!=0)
                            {
                                m_f_index = mindex2;
                                m_b_index = mindex;
                            }
                        }
                    }
                }
            }

            if(angle>0)//从左向右运动
            {
                if(angle<45)
                {
                    //后
                    gl.glPushMatrix();
                    gl.glTranslatef(0, 0, -radius);
                    gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //右
                    gl.glPushMatrix();
                    gl.glTranslatef(radius, 0, 0);
                    gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //左
                    gl.glPushMatrix();
                    gl.glTranslatef(-radius, -1.0f*gettrans_l(angle), 0);
                    gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //前
                    gl.glPushMatrix();
                    gl.glTranslatef(0, -1.0f*gettrans_f(angle), radius);
                    gl.glScalef(1.0f*getscale_f(angle), 1.0f*getscale_f(angle), 1.0f*getscale_f(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mTextureRectList.get(m_f_index).drawSelf(gl);
                    gl.glPopMatrix();

                    m_b_big = false;
                    m_l_big = false;
                    m_f_big = true;
                    m_r_big = false;

                } else {
                    if(angle<90)
                    {
                        //右
                        gl.glPushMatrix();
                        gl.glTranslatef(radius, 0, 0);
                        gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                        gl.glPopMatrix();
                        //后
                        gl.glPushMatrix();
                        gl.glTranslatef(0, 0, -radius);
                        gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                        gl.glPopMatrix();
                        //前
                        gl.glPushMatrix();
                        gl.glTranslatef(0, -1.0f*gettrans_f(angle), radius);
                        gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                        gl.glPopMatrix();
                        //左
                        gl.glPushMatrix();
                        gl.glTranslatef(-radius, -1.0f*gettrans_l(angle), 0);
                        gl.glScalef(1.0f*getscale_l(angle), 1.0f*getscale_l(angle), 1.0f*getscale_l(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mTextureRectList.get(m_l_index).drawSelf(gl);
                        gl.glPopMatrix();

                        m_b_big = false;
                        m_l_big = true;
                        m_f_big = false;
                        m_r_big = false;
                    } else {
                        if(angle<135)
                        {
                            //右
                            gl.glPushMatrix();
                            gl.glTranslatef(radius, 0, 0);
                            gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                            gl.glPopMatrix();
                            //前
                            gl.glPushMatrix();
                            gl.glTranslatef(0, 0, radius);
                            gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                            gl.glPopMatrix();
                            //后
                            gl.glPushMatrix();
                            gl.glTranslatef(0, -1.0f*gettrans_b(angle), -radius);
                            gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                            gl.glPopMatrix();
                            //左
                            gl.glPushMatrix();
                            gl.glTranslatef(-radius, -1.0f*gettrans_l(angle), 0);
                            gl.glScalef(1.0f*getscale_l(angle), 1.0f*getscale_l(angle), 1.0f*getscale_l(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mTextureRectList.get(m_l_index).drawSelf(gl);
                            gl.glPopMatrix();

                            m_b_big = false;
                            m_l_big = true;
                            m_f_big = false;
                            m_r_big = false;
                        } else {
                            if(angle<180)
                            {
                                //前
                                gl.glPushMatrix();
                                gl.glTranslatef(0, 0, radius);
                                gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                gl.glPopMatrix();
                                //右
                                gl.glPushMatrix();
                                gl.glTranslatef(radius, 0, 0);
                                gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                gl.glPopMatrix();
                                //左
                                gl.glPushMatrix();
                                gl.glTranslatef(-radius, -1.0f*gettrans_l(angle), 0);
                                gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                gl.glPopMatrix();
                                //后
                                gl.glPushMatrix();
                                gl.glTranslatef(0, -1.0f*gettrans_b(angle), -radius);
                                gl.glScalef(1.0f*getscale_b(angle), 1.0f*getscale_b(angle), 1.0f*getscale_b(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mTextureRectList.get(m_b_index).drawSelf(gl);
                                gl.glPopMatrix();

                                m_b_big = true;
                                m_l_big = false;
                                m_f_big = false;
                                m_r_big = false;
                            } else {
                                if(angle<225)
                                {
                                    //前
                                    gl.glPushMatrix();
                                    gl.glTranslatef(0, 0, radius);
                                    gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                    gl.glPopMatrix();
                                    //左
                                    gl.glPushMatrix();
                                    gl.glTranslatef(-radius, 0, 0);
                                    gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                    gl.glPopMatrix();
                                    //右
                                    gl.glPushMatrix();
                                    gl.glTranslatef(radius, -1.0f*gettrans_r(angle), 0);
                                    gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                    gl.glPopMatrix();
                                    //后
                                    gl.glPushMatrix();
                                    gl.glTranslatef(0, -1.0f*gettrans_b(angle), -radius);
                                    gl.glScalef(1.0f*getscale_b(angle), 1.0f*getscale_b(angle), 1.0f*getscale_b(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mTextureRectList.get(m_b_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    m_b_big = true;
                                    m_l_big = false;
                                    m_f_big = false;
                                    m_r_big = false;
                                } else {
                                    if(angle<270)
                                    {
                                        //左
                                        gl.glPushMatrix();
                                        gl.glTranslatef(-radius, 0, 0);
                                        gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                        gl.glPopMatrix();
                                        //前
                                        gl.glPushMatrix();
                                        gl.glTranslatef(0, 0, radius);
                                        gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                        gl.glPopMatrix();
                                        //后
                                        gl.glPushMatrix();
                                        gl.glTranslatef(0, -1.0f*gettrans_b(angle), -radius);
                                        gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                                        gl.glPopMatrix();
                                        //右
                                        gl.glPushMatrix();
                                        gl.glTranslatef(radius, -1.0f*gettrans_r(angle), 0);
                                        gl.glScalef(1.0f*getscale_r(angle), 1.0f*getscale_r(angle), 1.0f*getscale_r(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mTextureRectList.get(m_r_index).drawSelf(gl);
                                        gl.glPopMatrix();

                                        m_b_big = false;
                                        m_l_big = false;
                                        m_f_big = false;
                                        m_r_big = true;
                                    } else {
                                        if(angle<315)
                                        {
                                            //左
                                            gl.glPushMatrix();
                                            gl.glTranslatef(-radius, 0, 0);
                                            gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            //后
                                            gl.glPushMatrix();
                                            gl.glTranslatef(0, 0, -radius);
                                            gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            //前
                                            gl.glPushMatrix();
                                            gl.glTranslatef(0, -1.0f*gettrans_f(angle), radius);
                                            gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            //右
                                            gl.glPushMatrix();
                                            gl.glTranslatef(radius, -1.0f*gettrans_r(angle), 0);
                                            gl.glScalef(1.0f*getscale_r(angle), 1.0f*getscale_r(angle), 1.0f*getscale_r(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mTextureRectList.get(m_r_index).drawSelf(gl);
                                            gl.glPopMatrix();

                                            m_b_big = false;
                                            m_l_big = false;
                                            m_f_big = false;
                                            m_r_big = true;
                                        } else {
                                            //后
                                            gl.glPushMatrix();
                                            gl.glTranslatef(0, 0, -radius);
                                            gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            //左
                                            gl.glPushMatrix();
                                            gl.glTranslatef(-radius, 0, 0);
                                            gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            //右
                                            gl.glPushMatrix();
                                            gl.glTranslatef(radius, -1.0f*gettrans_r(angle), 0);
                                            gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            //前
                                            gl.glPushMatrix();
                                            gl.glTranslatef(0, -1.0f*gettrans_f(angle), radius);
                                            gl.glScalef(1.0f*getscale_f(angle), 1.0f*getscale_f(angle), 1.0f*getscale_f(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mTextureRectList.get(m_f_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            m_b_big = false;
                                            m_l_big = false;
                                            m_f_big = true;
                                            m_r_big = false;
                                        }
                                    }

                                }
                            }
                        }
                    }
                }

            } else {//从右往左运动
                if(Math.abs(angle)<45)
                {
                    //后
                    gl.glPushMatrix();
                    gl.glTranslatef(0, 0, -radius);
                    gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                    gl.glPopMatrix();



                    //左
                    gl.glPushMatrix();
                    gl.glTranslatef(-radius, 0, 0);
                    gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //右
                    gl.glPushMatrix();
                    gl.glTranslatef(radius, -1.0f*gettrans_r(angle), 0);
                    gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                    gl.glPopMatrix();

                    //前
                    gl.glPushMatrix();
                    gl.glTranslatef(0, -1.0f*gettrans_f(angle), radius);
                    gl.glScalef(1.0f*getscale_f(angle), 1.0f*getscale_f(angle), 1.0f*getscale_f(angle));
                    gl.glRotatef(-angle, 0, 1, 0);
                    mTextureRectList.get(m_f_index).drawSelf(gl);
                    gl.glPopMatrix();

                    m_b_big = false;
                    m_l_big = false;
                    m_f_big = true;
                    m_r_big = false;
                } else {

                    if(Math.abs(angle)<90){



                        //左
                        gl.glPushMatrix();
                        gl.glTranslatef(-radius, 0, 0);
                        gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                        gl.glPopMatrix();

                        //后
                        gl.glPushMatrix();
                        gl.glTranslatef(0, 0, -radius);
                        gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                        gl.glPopMatrix();

                        //前
                        gl.glPushMatrix();
                        gl.glTranslatef(0, -1.0f*gettrans_f(angle), radius);
                        gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                        gl.glPopMatrix();




                        //右
                        gl.glPushMatrix();
                        gl.glTranslatef(radius, -1.0f*gettrans_r(angle), 0);
                        gl.glScalef(1.0f*getscale_r(angle), 1.0f*getscale_r(angle), 1.0f*getscale_r(angle));
                        gl.glRotatef(-angle, 0, 1, 0);
                        mTextureRectList.get(m_r_index).drawSelf(gl);
                        gl.glPopMatrix();

                        m_b_big = false;
                        m_l_big = false;
                        m_f_big = false;
                        m_r_big = true;
                    } else {
                        if(Math.abs(angle)<135)
                        {

                            //左
                            gl.glPushMatrix();
                            gl.glTranslatef(-radius, 0, 0);
                            gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                            gl.glPopMatrix();

                            //前
                            gl.glPushMatrix();
                            gl.glTranslatef(0, 0, radius);
                            gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                            gl.glPopMatrix();

                            //后
                            gl.glPushMatrix();
                            gl.glTranslatef(0, -1.0f*gettrans_b(angle), -radius);
                            gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                            gl.glPopMatrix();


                            //右
                            gl.glPushMatrix();
                            gl.glTranslatef(radius, -1.0f*gettrans_r(angle), 0);
                            gl.glScalef(1.0f*getscale_r(angle), 1.0f*getscale_r(angle), 1.0f*getscale_r(angle));
                            gl.glRotatef(-angle, 0, 1, 0);
                            mTextureRectList.get(m_r_index).drawSelf(gl);
                            gl.glPopMatrix();

                            m_b_big = false;
                            m_l_big = false;
                            m_f_big = false;
                            m_r_big = true;


                        } else {

                            if(Math.abs(angle)<180){
                                //前
                                gl.glPushMatrix();
                                gl.glTranslatef(0, 0, radius);
                                gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                gl.glPopMatrix();
                                //左
                                gl.glPushMatrix();
                                gl.glTranslatef(-radius, 0, 0);
                                gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                gl.glPopMatrix();

                                //右
                                gl.glPushMatrix();
                                gl.glTranslatef(radius, -1.0f*gettrans_r(angle), 0);
                                gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                gl.glPopMatrix();
                                //后
                                gl.glPushMatrix();
                                gl.glTranslatef(0, -1.0f*gettrans_b(angle), -radius);
                                gl.glScalef(1.0f*getscale_b(angle), 1.0f*getscale_b(angle), 1.0f*getscale_b(angle));
                                gl.glRotatef(-angle, 0, 1, 0);
                                mTextureRectList.get(m_b_index).drawSelf(gl);
                                gl.glPopMatrix();

                                m_b_big = true;
                                m_l_big = false;
                                m_f_big = false;
                                m_r_big = false;
                            } else {

                                if(Math.abs(angle)<225){

                                    //前
                                    gl.glPushMatrix();
                                    gl.glTranslatef(0, 0, radius);
                                    gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                    gl.glPopMatrix();
                                    //右
                                    gl.glPushMatrix();
                                    gl.glTranslatef(radius, 0, 0);
                                    gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                    gl.glPopMatrix();




                                    //左
                                    gl.glPushMatrix();
                                    gl.glTranslatef(-radius, -1.0f*gettrans_l(angle), 0);
                                    gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    //后
                                    gl.glPushMatrix();
                                    gl.glTranslatef(0, -1.0f*gettrans_b(angle), -radius);
                                    gl.glScalef(1.0f*getscale_b(angle), 1.0f*getscale_b(angle), 1.0f*getscale_b(angle));
                                    gl.glRotatef(-angle, 0, 1, 0);
                                    mTextureRectList.get(m_b_index).drawSelf(gl);
                                    gl.glPopMatrix();

                                    m_b_big = true;
                                    m_l_big = false;
                                    m_f_big = false;
                                    m_r_big = false;
                                } else {
                                    if(Math.abs(angle)<270){
                                        //右
                                        gl.glPushMatrix();
                                        gl.glTranslatef(radius, 0, 0);
                                        gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                        gl.glPopMatrix();
                                        //前
                                        gl.glPushMatrix();
                                        gl.glTranslatef(0, 0, radius);
                                        gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                        gl.glPopMatrix();



                                        //后
                                        gl.glPushMatrix();
                                        gl.glTranslatef(0, -1.0f*gettrans_b(angle), -radius);
                                        gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                                        gl.glPopMatrix();

                                        //左
                                        gl.glPushMatrix();
                                        gl.glTranslatef(-radius, -1.0f*gettrans_l(angle), 0);
                                        gl.glScalef(1.0f*getscale_l(angle), 1.0f*getscale_l(angle), 1.0f*getscale_l(angle));
                                        gl.glRotatef(-angle, 0, 1, 0);
                                        mTextureRectList.get(m_l_index).drawSelf(gl);
                                        gl.glPopMatrix();

                                        m_b_big = false;
                                        m_l_big = true;
                                        m_f_big = false;
                                        m_r_big = false;

                                    } else {
                                        if(Math.abs(angle)<315){

                                            //右
                                            gl.glPushMatrix();
                                            gl.glTranslatef(radius, 0, 0);
                                            gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            //后
                                            gl.glPushMatrix();
                                            gl.glTranslatef(0, 0, -radius);
                                            gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                                            gl.glPopMatrix();

                                            //前
                                            gl.glPushMatrix();
                                            gl.glTranslatef(0, -1.0f*gettrans_f(angle), radius);
                                            gl.glScalef(1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle), 1.0f*getscale_f2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_f_index).drawSelf(gl);
                                            gl.glPopMatrix();




                                            //左
                                            gl.glPushMatrix();
                                            gl.glTranslatef(-radius, -1.0f*gettrans_l(angle), 0);
                                            gl.glScalef(1.0f*getscale_l(angle), 1.0f*getscale_l(angle), 1.0f*getscale_l(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mTextureRectList.get(m_l_index).drawSelf(gl);
                                            gl.glPopMatrix();

                                            m_b_big = false;
                                            m_l_big = true;
                                            m_f_big = false;
                                            m_r_big = false;
                                        } else {
                                            //后
                                            gl.glPushMatrix();
                                            gl.glTranslatef(0, 0, -radius);
                                            gl.glScalef(1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle), 1.0f*getscale_b2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_b_index).drawSelf(gl);
                                            gl.glPopMatrix();
                                            //右
                                            gl.glPushMatrix();
                                            gl.glTranslatef(radius, 0, 0);
                                            gl.glScalef(1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle), 1.0f*getscale_r2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_r_index).drawSelf(gl);
                                            gl.glPopMatrix();


                                            //左
                                            gl.glPushMatrix();
                                            gl.glTranslatef(-radius, -1.0f*gettrans_l(angle), 0);
                                            gl.glScalef(1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle), 1.0f*getscale_l2(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mBlurTextureRectList.get(m_l_index).drawSelf(gl);
                                            gl.glPopMatrix();





                                            //前
                                            gl.glPushMatrix();
                                            gl.glTranslatef(0, -1.0f*gettrans_f(angle), radius);
                                            gl.glScalef(1.0f*getscale_f(angle), 1.0f*getscale_f(angle), 1.0f*getscale_f(angle));
                                            gl.glRotatef(-angle, 0, 1, 0);
                                            mTextureRectList.get(m_f_index).drawSelf(gl);
                                            gl.glPopMatrix();

                                            m_b_big = false;
                                            m_l_big = false;
                                            m_f_big = true;
                                            m_r_big = false;
                                        }
                                    }
                                }
                            }

                        }
                    }
                }
            }

            //TODO:

            if(m_current_sel_index!=showSel()) {
                m_current_sel_index = showSel();

                icallBack.onSelected(m_current_sel_index);
            }

            mindex = m_current_sel_index + 1;
            mindex2 = m_current_sel_index - 1;

            if((mindex - (mTextureRectList.size()-1)) == 1 )
            {
                mindex = 0;
            } else {
                if((mindex - (mTextureRectList.size()-1)) == 2)
                {
                    mindex = 1;
                } else {
                    if((mindex - (mTextureRectList.size()-1)) == 0)
                    {

                    }
                }
            }

            if((mindex2 - 0) == -1)
            {
                mindex2 = mTextureRectList.size()-1;
            } else {
                if((mindex2 - 0) == -2)
                {
                    mindex2 = mTextureRectList.size()-2;
                } else {
                    if((mindex2 - 0) == 2)
                    {

                    }
                }
            }
        }


        public void onDrawFrame(GL10 gl) {

            if(mInit)
            {
                mInit = false;
                m_b_index = 2;
                m_l_index = 3;
                m_f_index = 0;
                m_r_index = 1;
                mindex = 0;
                //初始化纹理
                initTextureList(gl);
            }

            //设置为打开背面剪裁
            gl.glEnable(GL10.GL_BLEND);

            //设置着色模型为平滑着色
            gl.glShadeModel(GL10.GL_SMOOTH);




            //清除颜色缓存于深度缓存
            gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
            //设置当前矩阵为模式矩阵
            gl.glMatrixMode(GL10.GL_MODELVIEW);
            //设置当前矩阵为单位矩阵
            gl.glLoadIdentity();


            gl.glEnable(GL10.GL_BLEND);
            gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

            //设置camera位置=======================
            GLU.gluLookAt//不太可能变形的视角——小视角
                    (
                            gl,
                            0f,   //人眼位置的X
                            4.0f, 	//人眼位置的Y
                            14.0f,   //人眼位置的Z
                            0, 	//人眼球看的点X
                            0f,   //人眼球看的点Y
                            0,   //人眼球看的点Z
                            0,
                            1,
                            0
                    );

            gl.glPushMatrix();
            gl.glTranslatef(0, -3f, -10f);
            trOneXOne.drawSelf(gl);
            gl.glPopMatrix();

            //旋转总坐标系
            gl.glRotatef(angle, 0, 1, 0);

            gl.glTranslatef(0, 1.5f, 0f);//整体移动

            //if(mTextureRectList==null||mTextureRectList.size()<4)
            if(mReLoadTexture)
            {
                return;
            }

            if (mBlurTextureRectList.isEmpty())
                return;

            if(m_num_type==3){
                rotation3Objects(gl);
            } else {
                rotation4Objects(gl);
            }

        }



        public void onSurfaceChanged(GL10 gl, int width, int height) {
            //设置视窗大小及位置
            gl.glViewport(0, 0, width, height);
            //设置当前矩阵为投影矩阵
            gl.glMatrixMode(GL10.GL_PROJECTION);
            //gl.glMatrixMode(GL10.GL_MODELVIEW);
            //设置当前矩阵为单位矩阵
            gl.glLoadIdentity();
            //计算透视投影的比例
            float ratio = (float) height/width ;

            //调用此方法计算产生透视投影矩阵
//            gl.glFrustumf( -1, 1,-ratio, ratio, 1, 100);   //可能变形的视角——大视角
            gl.glFrustumf( -1, 1,-ratio, ratio, 5.5f, 100);     //不太可能变形的视角——小视角

            int backgroundid = initTexture(gl, R.drawable.bg_create_made);
            mRenderer.trOneXOne = new TextureRect(5f,9f,backgroundid,1,1,0);
        }

        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
//            Log.e("onSurfaceCreated", "hit");
            //关闭抗抖动
            gl.glDisable(GL10.GL_DITHER);
            //设置特定Hint项目的模式，这里为设置为使用快速模式
            gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
            //设置屏幕背景色白色RGBA
            gl.glClearColor(255,255,255,1);
//            gl.glClearColor(0,0,0,0);
            //启用深度测试
            gl.glEnable(GL10.GL_DEPTH_TEST);

        }
    }

    //TODO: update data from here
    private ArrayList<Bitmap> DrawableIdList;
    public void reinitTextureList(ArrayList<Bitmap> list)
    {
        if(DrawableIdList!=null)
        {
            DrawableIdList.clear();
        } else {
            DrawableIdList = new ArrayList<Bitmap>();
        }
        DrawableIdList.addAll(list);
        mRenderer.mReLoadTexture = true;
        if (DrawableIdList.size() >= 4){
            mRenderer.m_num_type = 4;
        } else {
            mRenderer.m_num_type = 3;
        }
        LogUtil.d("image_size-2049 = " +DrawableIdList.size());

//        new AsyncTask<Integer, Integer, Integer>() {
//
//            @Override
//            protected Integer doInBackground(Integer... params) {
//                try {
//                    //睡眠2秒
//                    Thread.sleep(2000);
//

//                    for(int i=m_dummy_index; i<10; i++){
//                        switch(i%6)
//                        {
//                            case 0:
//                                DrawableIdList.add(R.drawable.gl_text_01);
//
//                                break;
//                            case 1:
//                                DrawableIdList.add(R.drawable.gl_text_02);
//                                break;
//                            case 2:
//                                DrawableIdList.add(R.drawable.gl_text_03);
//                                break;
//                            case 3:
//                                DrawableIdList.add(R.drawable.gl_text_04);
//                                break;
//                            case 4:
//                                DrawableIdList.add(R.drawable.gl_text_05);
//                                break;
//                            case 5:
//                                DrawableIdList.add(R.drawable.gl_text_06);
//                                break;
//                        }
//                    }
//
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }

//                if(m_dummy_index<4)
//                {
//                    m_dummy_index++;
//                } else {
//                    m_dummy_index = 0;
//                }
//                return null;
//            }

//            protected void onPostExecute(Integer result) {
////                Log.e("reinitTextureList", String.valueOf(DrawableIdList.size()));
                mRenderer.mInit = true;
//            };
//        }.execute();



    }

    private int m_dummy_index=0;


    public void initTextureList(GL10 gl)
    {
//        Log.e("initTextureList", "hit");


        if(mRenderer.mTextureRectList!=null)
        {
            mRenderer.mTextureRectList.clear();
            mRenderer.mTextureRectList = null;
        }
        mRenderer.mTextureRectList = new ArrayList<TextureRect>();

        if(mRenderer.mBlurTextureRectList!=null)
        {
            mRenderer.mBlurTextureRectList.clear();
            mRenderer.mBlurTextureRectList = null;
        }
        mRenderer.mBlurTextureRectList = new ArrayList<TextureRect>();


        int testTexId;
        TextureRect trOneXOne;

//        mRenderer.m_num_type = (mRenderer.m_num_type==4) ? 3: 4;

        if(DrawableIdList!=null&&DrawableIdList.size()>0)
        {
//            Log.e("initTextureList", String.valueOf(DrawableIdList.size()));

            if(mRenderer.m_num_type==3)
            {
                for(int i=0; i<3; i++)
                {
                    testTexId=initTexture(gl,DrawableIdList.get(i));
                    //创建纹理矩形
                    trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
                    mRenderer.mTextureRectList.add(trOneXOne);
                    testTexId=initTextureWithBlur(gl,DrawableIdList.get(i));
                    //创建纹理矩形
                    trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
                    mRenderer.mBlurTextureRectList.add(trOneXOne);
                }
            } else {
                for(int i=0; i<DrawableIdList.size(); i++)
                {
                    testTexId=initTexture(gl,DrawableIdList.get(i));
                    //创建纹理矩形
                    trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
                    mRenderer.mTextureRectList.add(trOneXOne);
                    testTexId=initTextureWithBlur(gl,DrawableIdList.get(i));
                    //创建纹理矩形
                    trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
                    mRenderer.mBlurTextureRectList.add(trOneXOne);
                }
            }



        } else {

//            Log.e("initTextureList", "DrawableIdList is null");
//            for(int i=0; i<10; i++)
//            {
//
//                switch(i%6)
//                {
//                    case 0:
//                        testTexId=initTexture(gl,R.drawable.gl_text_01);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mTextureRectList.add(trOneXOne);
//
//                        testTexId=initTextureWithBlur(gl,R.drawable.gl_text_01);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mBlurTextureRectList.add(trOneXOne);
//                        break;
//                    case 1:
//                        testTexId=initTexture(gl,R.drawable.gl_text_02);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mTextureRectList.add(trOneXOne);
//
//                        testTexId=initTextureWithBlur(gl,R.drawable.gl_text_02);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mBlurTextureRectList.add(trOneXOne);
//                        break;
//                    case 2:
//                        testTexId=initTexture(gl,R.drawable.gl_text_03);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mTextureRectList.add(trOneXOne);
//
//                        testTexId=initTextureWithBlur(gl,R.drawable.gl_text_03);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mBlurTextureRectList.add(trOneXOne);
//                        break;
//                    case 3:
//                        testTexId=initTexture(gl,R.drawable.gl_text_04);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mTextureRectList.add(trOneXOne);
//
//                        testTexId=initTextureWithBlur(gl,R.drawable.gl_text_04);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mBlurTextureRectList.add(trOneXOne);
//                        break;
//                    case 4:
//                        testTexId=initTexture(gl,R.drawable.gl_text_05);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mTextureRectList.add(trOneXOne);
//
//                        testTexId=initTextureWithBlur(gl,R.drawable.gl_text_05);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mBlurTextureRectList.add(trOneXOne);
//                        break;
//                    case 5:
//                        testTexId=initTexture(gl,R.drawable.gl_text_06);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mTextureRectList.add(trOneXOne);
//
//                        testTexId=initTextureWithBlur(gl,R.drawable.gl_text_06);
//                        //创建纹理矩形
//                        trOneXOne=new TextureRect(1.5f,1.5f,testTexId,1,1,i);//s-t  0-1
//                        mRenderer.mBlurTextureRectList.add(trOneXOne);
//                        break;
//                }
//            }
        }

        reinitPageTextureList();

        mRenderer.mReLoadTexture = false;
        if (icallBack != null){
            icallBack.onInitDone("Texture Done");
        }
    }

    private void reinitPageTextureList()
    {
        mRenderer.angle = 0;
    }

    //初始化纹理
    public int initTexture(GL10 gl,int textureId)//textureId
    {
        //生成纹理ID
        int[] textures = new int[1];
        gl.glGenTextures(1, textures, 0);
        int currTextureId = textures[0];
        gl.glBindTexture(GL10.GL_TEXTURE_2D, currTextureId);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_NEAREST);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR);


        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_CLAMP_TO_EDGE);//拉大模式
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_CLAMP_TO_EDGE);
        //设置纹理拉伸方式为重复
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_REPEAT);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_REPEAT);

//        InputStream is = this.getResources().openRawResource(textureId);
        Bitmap bitmapTmp;
//        try
//        {
//            bitmapTmp = BitmapFactory.decodeStream(is);
            bitmapTmp = BitmapFactory.decodeResource(getContext().getResources(), textureId);
            bitmapTmp = Bitmap.createScaledBitmap(bitmapTmp,512,512,true);
//        }
//        finally
//        {
//            try
//            {
//                is.close();
//            }
//            catch(IOException e)
//            {
//                e.printStackTrace();
//            }
//        }

        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmapTmp, 0);
        bitmapTmp.recycle();

        return currTextureId;
    }

    //初始化纹理
    public int initTexture(GL10 gl,Bitmap bitmapTmp)//textureId
    {
        //生成纹理ID
        int[] textures = new int[1];
        gl.glGenTextures(1, textures, 0);
        int currTextureId = textures[0];
        gl.glBindTexture(GL10.GL_TEXTURE_2D, currTextureId);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_NEAREST);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR);


        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_CLAMP_TO_EDGE);//拉大模式
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_CLAMP_TO_EDGE);
        //设置纹理拉伸方式为重复
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_REPEAT);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_REPEAT);
//
//        InputStream is = this.getResources().openRawResource(textureId);
//        Bitmap bitmapTmp;
//        try
//        {
//            bitmapTmp = BitmapFactory.decodeStream(is);
//        }
//        finally
//        {
//            try
//            {
//                is.close();
//            }
//            catch(IOException e)
//            {
//                e.printStackTrace();
//            }
//        }

        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmapTmp, 0);
//        bitmapTmp.recycle();

        return currTextureId;
    }

    //初始化纹理
    public int initTextureWithBlur(GL10 gl,Bitmap bitmap)//textureId
    {
        //生成纹理ID
        int[] textures = new int[1];
        gl.glGenTextures(1, textures, 0);
        int currTextureId=textures[0];
        gl.glBindTexture(GL10.GL_TEXTURE_2D, currTextureId);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_NEAREST);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR);


        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_CLAMP_TO_EDGE);//拉大模式
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_CLAMP_TO_EDGE);
        //设置纹理拉伸方式为重复
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,GL10.GL_REPEAT);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,GL10.GL_REPEAT);

//        InputStream is = this.getResources().openRawResource(drawableId);
//        Bitmap bitmapTmp;
//        try
//        {
//            bitmapTmp = BitmapFactory.decodeStream(is);
//        }
//        finally
//        {
//            try
//            {
//                is.close();
//            }
//            catch(IOException e)
//            {
//                e.printStackTrace();
//            }
//        }
        String phoneModel = Build.MODEL;
//        if ( phoneModel.contains("MX4 Pro") || phoneModel.contains("MI 2") || phoneModel.contains("2013023") || phoneModel.contains("H30-U10")){//针对mx4 pro特殊处理高斯模糊
//            GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, fastblur(this.getContext(), bitmap,6), 0);
//        } else {
            GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, blur(bitmap,16), 0);
//        }
//        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

        //GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmapTmp, 0);
        //GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, blur2(bitmapTmp,16), 0);
//        bitmap.recycle();

        return currTextureId;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private Bitmap blur2(Bitmap sentBitmap, float radius) {
        if (VERSION.SDK_INT > 16) {
            Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);

            final RenderScript rs = RenderScript.create(this.getContext());
            final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
                    Allocation.USAGE_SCRIPT);
            final Allocation output = Allocation.createTyped(rs, input.getType());
            final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            script.setRadius(radius /* e.g. 3.f */);
            script.setInput(input);
            script.forEach(output);
            output.copyTo(bitmap);
            return bitmap;
        } else {
            return fastblur(this.getContext(), sentBitmap, (int)radius);
        }
    }

    @SuppressLint("NewApi")
    public static Bitmap fastblur(Context context, Bitmap sentBitmap, int radius) {


        Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);

        if (radius < 1) {
            return (null);
        }

        int w = bitmap.getWidth();
        int h = bitmap.getHeight();

        int[] pix = new int[w * h];
//        Log.e("pix", w + " " + h + " " + pix.length);
        bitmap.getPixels(pix, 0, w, 0, 0, w, h);

        int wm = w - 1;
        int hm = h - 1;
        int wh = w * h;
        int div = radius + radius + 1;

        int r[] = new int[wh];
        int g[] = new int[wh];
        int b[] = new int[wh];
        int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
        int vmin[] = new int[Math.max(w, h)];

        int divsum = (div + 1) >> 1;
        divsum *= divsum;
        int temp = 256 * divsum;
        int dv[] = new int[temp];
        for (i = 0; i < temp; i++) {
            dv[i] = (i / divsum);
        }

        yw = yi = 0;

        int[][] stack = new int[div][3];
        int stackpointer;
        int stackstart;
        int[] sir;
        int rbs;
        int r1 = radius + 1;
        int routsum, goutsum, boutsum;
        int rinsum, ginsum, binsum;

        for (y = 0; y < h; y++) {
            //if(y>(h/2-10)&&y<(h/2+10))
            {
                rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
                for (i = -radius; i <= radius; i++) {
                    p = pix[yi + Math.min(wm, Math.max(i, 0))];
                    sir = stack[i + radius];
                    sir[0] = (p & 0xff0000) >> 16;
                    sir[1] = (p & 0x00ff00) >> 8;
                    sir[2] = (p & 0x0000ff);
                    rbs = r1 - Math.abs(i);
                    rsum += sir[0] * rbs;
                    gsum += sir[1] * rbs;
                    bsum += sir[2] * rbs;
                    if (i > 0) {
                        rinsum += sir[0];
                        ginsum += sir[1];
                        binsum += sir[2];
                    } else {
                        routsum += sir[0];
                        goutsum += sir[1];
                        boutsum += sir[2];
                    }
                }
                stackpointer = radius;

                for (x = 0; x < w; x++) {
                    //if(x>(w/2-10)&&x<(w/2+10))
                    {
                        r[yi] = dv[rsum];
                        g[yi] = dv[gsum];
                        b[yi] = dv[bsum];

                        rsum -= routsum;
                        gsum -= goutsum;
                        bsum -= boutsum;

                        stackstart = stackpointer - radius + div;
                        sir = stack[stackstart % div];

                        routsum -= sir[0];
                        goutsum -= sir[1];
                        boutsum -= sir[2];

                        if (y == 0) {
                            vmin[x] = Math.min(x + radius + 1, wm);
                        }
                        p = pix[yw + vmin[x]];

                        sir[0] = (p & 0xff0000) >> 16;
                        sir[1] = (p & 0x00ff00) >> 8;
                        sir[2] = (p & 0x0000ff);

                        rinsum += sir[0];
                        ginsum += sir[1];
                        binsum += sir[2];

                        rsum += rinsum;
                        gsum += ginsum;
                        bsum += binsum;

                        stackpointer = (stackpointer + 1) % div;
                        sir = stack[(stackpointer) % div];

                        routsum += sir[0];
                        goutsum += sir[1];
                        boutsum += sir[2];

                        rinsum -= sir[0];
                        ginsum -= sir[1];
                        binsum -= sir[2];

                        yi++;
                    }
                }
                yw += w;
            }
        }
        for (x = 0; x < w; x++) {
            //if(x>(w/2-10)&&x<(w/2+10))
            {
                rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
                yp = -radius * w;
                for (i = -radius; i <= radius; i++) {
                    yi = Math.max(0, yp) + x;

                    sir = stack[i + radius];

                    sir[0] = r[yi];
                    sir[1] = g[yi];
                    sir[2] = b[yi];

                    rbs = r1 - Math.abs(i);

                    rsum += r[yi] * rbs;
                    gsum += g[yi] * rbs;
                    bsum += b[yi] * rbs;

                    if (i > 0) {
                        rinsum += sir[0];
                        ginsum += sir[1];
                        binsum += sir[2];
                    } else {
                        routsum += sir[0];
                        goutsum += sir[1];
                        boutsum += sir[2];
                    }

                    if (i < hm) {
                        yp += w;
                    }
                }
                yi = x;
                stackpointer = radius;
                for (y = 0; y < h; y++) {
                    //if(y>(h/2-10)&&y<(h/2+10))
                    {
                        // Preserve alpha channel: ( 0xff000000 & pix[yi] )
                        pix[yi] = (0xef000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
                        //pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];

                        rsum -= routsum;
                        gsum -= goutsum;
                        bsum -= boutsum;

                        stackstart = stackpointer - radius + div;
                        sir = stack[stackstart % div];

                        routsum -= sir[0];
                        goutsum -= sir[1];
                        boutsum -= sir[2];

                        if (x == 0) {
                            vmin[y] = Math.min(y + r1, hm) * w;
                        }
                        p = x + vmin[y];

                        sir[0] = r[p];
                        sir[1] = g[p];
                        sir[2] = b[p];

                        rinsum += sir[0];
                        ginsum += sir[1];
                        binsum += sir[2];

                        rsum += rinsum;
                        gsum += ginsum;
                        bsum += binsum;

                        stackpointer = (stackpointer + 1) % div;
                        sir = stack[stackpointer];

                        routsum += sir[0];
                        goutsum += sir[1];
                        boutsum += sir[2];

                        rinsum -= sir[0];
                        ginsum -= sir[1];
                        binsum -= sir[2];

                        yi += w;
                    }
                }
            }
        }

//        Log.e("pix", w + " " + h + " " + pix.length);

//        int pix_index = 0;
//        for(int j= 0; j<h; j++)
//        {
//        	if(j<(100)||j>(h-100))
//        	{
//        		for(int k=0; k<w; k++)
//        		{
//        			if(k<(100)||k>(w-100))
//        			{
//	        			pix_index = j*w +k;
//	        			if(pix[pix_index]!=0x00000000)
//	        			{
//	        				pix[pix_index] = 0x0000000;
//	        			}
//        			}
//        		}
//        	}
//        }

//        	int temp1;
//	      for(int j= 0; j<h; j++)
//	      {
//	    	  if(j<(60)||j>(h-60)){
//		      		for(int k=0; k<w; k++)
//		      		{
//		      			if(k<(100)||k>(w-100))
//		      			{
//		        			pix_index = j*w +k;
//		        			if(pix[pix_index]!=0x00000000)
//		        			{
//		        				temp1 = pix[pix_index]&0x00ffffff;
//		        				pix[pix_index] = temp1|0x22000000;
//		        			}
//		      			}
//		      		}
//	    	  }
//	      }

        bitmap.setPixels(pix, 0, w, 0, 0, w, h);
        return (bitmap);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private Bitmap blur(Bitmap bkg, float radius) {
        Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(),
                Bitmap.Config.ARGB_8888);
        try {
            RenderScript rs = RenderScript.create(getContext());

            Allocation allIn = Allocation.createFromBitmap(rs, bkg);

            Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay);
            //ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
            blur.setInput(allIn);
            blur.setRadius(radius);
            blur.forEach(overlayAlloc);
            overlayAlloc.copyTo(overlay);
            rs.destroy();
        }catch (NoClassDefFoundError e){
            return fastblur(this.getContext(),bkg,6);
        } catch (Exception ex){
            return fastblur(this.getContext(),bkg,6);
        }
        return overlay;
    }

    /**
     * 一定一个接口
     */
    public interface ICoallBack{
        public void onInitDone(String s);
        public void onSelected(int position);

    }

    /**
     * 初始化接口变量
     */
    ICoallBack icallBack = null;

    /**
     * 自定义控件的自定义事件
     * @param iBack 接口类型
     */
    public void setonInitDone(ICoallBack iBack)
    {
        icallBack = iBack;
    }
}